namespace IBS.Tests

open System
open FsUnit 
open NUnit.Framework
open IBS.Model.ExternalDataService

module ExternalDataServiceTest =    
    [<Test>]
    let ``Yahoo current date EUR/USD & USD/EUR rates should be consistent``() =
        let eurusd = currentRates [|"EUR"|] "USD" Provider.Yahoo |> Seq.head
        let usdeur = currentRates [|"USD"|] "EUR" Provider.Yahoo |> Seq.head
        eurusd.Rate |> should (equalWithin 1e-3) (1M / usdeur.Rate)
    
    // precision is low, because google results can be different: it can return 1.2703 in one request and 1.2734 in the next one
    [<Test>]
    let ``Google current date EUR/USD & USD/EUR rates should be consistent``() =
        let eurusd = currentRates [|"EUR"|] "USD" Provider.Google |> Seq.head
        let usdeur = currentRates [|"USD"|] "EUR" Provider.Google |> Seq.head
        eurusd.Rate |> should (equalWithin 0.01) (1M / usdeur.Rate)
        
    [<Test>]
    let ``FED CAD rate as of 11/01/2012 should be equal to 0.9973``() =
        let eurusd = fetchRates [|"CAD"|] "USD" (DateTime(2012,11,1)) Provider.FED |> Seq.head
        eurusd.Rate |> should (equalWithin 1e-2) 0.9973M
    
    [<Test>]
    let ``NBRB EUR exchange rate as of 11/01/2012 is 11050``() =
        let rates = fetchRates [|"BYR"|] "EUR" (DateTime(2012,11,1)) Provider.NBRB
        rates.[0].Rate |> should (equalWithin 1e-3) 11050M
        
    [<Test>]
    let ``ECB current date EUR/USD & USD/EUR rates should be consistent``() =
        let eurusd = currentRates [|"EUR"|] "USD" Provider.Google |> Seq.head
        let usdeur = currentRates [|"USD"|] "EUR" Provider.Google |> Seq.head
        eurusd.Rate |> should (equalWithin 0.01) (1M / usdeur.Rate)
